﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LaserHarp
{

    class TextBoxArray : System.Collections.CollectionBase
    {
        private Control container;
        private int top;

        public TextBoxArray(Control host, int Yoffset)
        {
            container = host;
            top = Yoffset;
        }

        public TextBox AddNewTextBox()
        {
            // Create a new instance of the Button class.
            TextBox aTextBox = new TextBox();
            // Add the button to the collection's internal list.
            this.List.Add(aTextBox);
            // Add the button to the controls collection of the form 
            // referenced by the HostForm field.
            container.Controls.Add(aTextBox);
            // Set intial properties for the button object.
            aTextBox.Top = top;
            aTextBox.Left = 65 + 50 * (Count - 1);
            aTextBox.Width = 30;
            aTextBox.Tag = this.Count - 1;
            aTextBox.Text = "";
            return aTextBox;
        }

        public TextBox this[int Index]
        {
            get
            {
                return (TextBox)this.List[Index];
            }
        }

        public void Remove()
        {
            // Check to be sure there is a box to remove.
            if (this.Count > 0)
            {
                // Remove the last button added to the array from the host form 
                // controls collection. Note the use of the indexer in accessing the array.
                container.Controls.Remove(this[this.Count - 1]);
                this.List.RemoveAt(this.Count - 1);
            }
        }
    }
}
